<!--工序搜索-->
<template>
  <div class="project-search-wrapper" ref="projectBoxRef">
    <a-table :scroll="{x:0,y:200}" :columns="columns" :data-source="tableData" :customRow="customClick" bordered :pagination="pagination" :loading="isSearch">
    </a-table>
  </div>
</template>
<script>
import { getAction } from "@/api/manage";

const columns = [
  {
    title: "工序编码",
    dataIndex: "code",
    width: "120"
  },
  {
    title: "工序名称",
    dataIndex: "name",
    width: "120"
  },
  {
    title: "加工方式",
    dataIndex: "processMethod",
    width: "120",
    customRender: (text, row, index) => {
      const type = ["自制", "委外"];
      return type[text - 1];
    }
  },
  {
    title: "工资类型",
    dataIndex: "wagesType",
    width: "120",
    customRender: (text, row, index) => {
      const type = ["计件", "计时", "不核算"];
      return type[text - 1];
    }
  },
  {
    title: "合格品价格",
    dataIndex: "qualifiedPrice",
    width: "120"
  },
];
export default {
  props: {

  },
  data () {
    return {
      pagination: {
        current: 1,
        pageSize: 20,
        total: 0,
        size: 'small',
        onChange: (page, pageSize) => {
          this.pagination.current = page;
          this.getData();
        }
      },
      columns,
      tableData: [],
      customClick: (record, index) => ({
        on: {
          click: (event) => {
            event.preventDefault();
            console.log('点击的行数', record, index);
            this.$emit('check', record)
          },
        },
      }),
      isSearch: false,
    }
  },
  created () {
    this.getData();
  },
  methods: {
    getData (code) {
      //获取右侧表数据
      let params = {
        current: this.pagination.current,
        size: this.pagination.pageSize,
      };
      if (!this.isSearch) {
        this.isSearch = true;
        getAction("/erp/workProcedure/pageList", params).then((response) => {
          if (response.code == 200) {
            const { records, total, current, size } = response.data;
            this.pagination.total = response.data.total;
            let page = {
              total: total,
              pageSize: size,
              current: current
            }
            this.pagination = Object.assign(this.pagination, page);
            this.tableData = records;
          } else {
            // this.$message.warning(response.message);
          }
          this.isSearch = false;
        });
      }

    },
    handleEnter () {
      if (this.tableData != '' && this.tableData != null) {
        this.$emit('check', this.tableData[0])
      } else {
        this.$message.warning('请选择一条数据')
        return;
      }
    },
    changePosition (position) {
      console.log(position);
      this.$nextTick(() => {
        this.$refs.projectBoxRef.style.left = (position.left - 200) + 'px';
        this.$refs.projectBoxRef.style.top = position.top + 'px';
      })
    }
  }
}
</script>
<style lang="less">
  .project-search-wrapper {
    max-height: 350px;
    position: fixed;
    z-index: 100;
    border: 1px solid #a7abb0;
    width: 500px;
    // .ant-table-wrapper .ant-table-placeholder {
    //   position: static !important;
    //   top: 0;
    // }
    .ant-table-wrapper {
      background: #eee;
    }
    .ant-table-tbody {
      cursor: pointer;
    }
  }
</style>